﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>改变 MsgBox 的按钮名称 - 脚本示例 | AutoHotkey v2</title>
<meta name="description" content="This script changes the names of the buttons in a MsgBox dialog using a timer." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Changing MsgBox's Button Names</h1>

<p>这是个可运行示例脚本, 它使用计时器改变 MsgBox 对话框中按钮的名称. 尽管改变了按钮名称, 但 MsgBox 的返回值仍然需要按钮引用它们原始的名称.
</p>
<p><a href="MsgBoxButtonNames.ahk">下载此脚本</a> &nbsp;| &nbsp;<a href="index.htm">其他示例脚本</a> &nbsp;| &nbsp;<a href="../AutoHotkey.htm">主页</a></p>

<pre class="NoIndent">#SingleInstance
SetTimer "ChangeButtonNames", 50
Result := MsgBox("Choose a button:", "Add or Delete", 4)
if Result = "Yes"
    MsgBox "You chose Add."
else
    MsgBox "You chose Delete."

ChangeButtonNames()
{
    if !WinExist("Add or Delete")
        return  <em>; Keep waiting.</em>
    SetTimer, 0
    WinActivate
    ControlSetText "&amp;Add", "Button1"
    ControlSetText "&amp;Delete", "Button2"
}
</pre>
</body>
</html>